<?php

/**
 * ApplicationBehavior class
 *
 * @author Julot <andy.julot@gmail.com>
 * @since Monday, January 30, 2012. 02:39 PM
 */
class ApplicationBehavior extends CBehavior {

	public function events() {
		$data = array('onBeginRequest'=>'beginRequest');
		return array_merge(parent::events(), $data);
	}

	public function beginRequest() {
		$owner = $this->owner;
		if (isset($_POST['_language'])) {
			$owner->user->setState('language', $_POST['_language']);
		}
		if ($owner->user->getState('language')) {
			$owner->language = $owner->user->getState('language');
		}
		else
			$owner->language = 'en';

		if (isset($_POST['_theme'])) {
			$owner->user->setState('theme', $_POST['_theme']);
		}
		if ($owner->user->getState('theme')) {
			$owner->theme = $owner->user->getState('theme');
		}
		else
			$owner->theme = 'chocolate-brown';
	}

}
